package com.briup.demo.service;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.demo.bean.CmsMember;
import com.briup.demo.mapper.CmsMemberMapper;

@Service
public class CmsMemberService {
	
	@Autowired
	private CmsMemberMapper memberMapper;

	public List<CmsMember> getAllMember(){
		List<CmsMember> list = memberMapper.selectAll();
		if(list!=null) {
			return list;
		}
		return new ArrayList<CmsMember>();
	}
	
	public int saveOrUpdate(CmsMember member) {
		if(member.getId()==null&&"".equals(member.getId())) {
			member.setId(UUID.randomUUID().toString());
			memberMapper.insert(member);
			return 1;
		}
		CmsMember cm = memberMapper.selectByPrimaryKey(member.getId());
		if(null!=cm){
			memberMapper.updateByPrimaryKey(member.getId());
			return 0;
		}else{
			return -1;
		}

	}
	
	public int deleteById(String id) { 
		int num = memberMapper.deleteByPrimaryKey(id);
		return num;
	}
	
	public CmsMember selectById(String id) {
		return memberMapper.selectByPrimaryKey(id); 
	}
	
	public boolean updateState(String memberId,String state) {
		int result = memberMapper.updateStateById(memberId, state);
		if(result==0) { 
			return false;
		}
		return true;
	}
}
